﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;

namespace WXYW
{
    public partial class TFSQSignList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTFSQGridView();
            }
        }

        protected void TFSQGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
        }

        protected void TFSQGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (e.NewPageIndex >= 0 && e.NewPageIndex < TFSQGridView.PageCount)
            {
                TFSQGridView.PageIndex = e.NewPageIndex;
            }
            
            BindTFSQGridView();
        }

        private void BindTFSQGridView()
        {
            SpecialServiceService service = new SpecialServiceService();
            if (ContextService.CurrentAccount.UserType.ID == (int)RoleType.Administrator ||                
                ContextService.CurrentAccount.UserType.ID == (int)RoleType.TBGLY)
            {
                TFSQGridView.DataSource = service.GetSpecialServiceApplicationListByStatus(Request.QueryString[Constants.QUERYSTR_STATUS]);
            }
            else
            {
                TFSQGridView.DataSource = service.GetSpecialServiceApplicationListByStatus(Request.QueryString[Constants.QUERYSTR_STATUS], ContextService.CurrentAccount);
            }
            TFSQGridView.DataBind();
        }

        protected void viewLinkButton_click(object sender, EventArgs e)
        {
            string applicationid = ((LinkButton)sender).CommandArgument;
            Response.Redirect(string.Format("TFSQSign.aspx?{0}={1}&{2}={3}", Constants.QUERYSTR_APPLICATION_ID, applicationid, 
                Constants.QUERYSTR_STATUS, Request.QueryString[Constants.QUERYSTR_STATUS]));
        }
    }
}
